//
//  MHAutoAddressViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/9/20.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHAutoAddressViewController.h"
#import "JKRSearchBar.h"
#import "MHCommonTableViewCell.h"
#import "JKRSearchController.h"
#import <AMapSearchKit/AMapSearchKit.h>

@interface MHAutoAddressViewController ()<JKRSearchBarDelegate>

@end

@implementation MHAutoAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.sectionIndexColor = [UIColor blueColor];
    self.tableView.sectionIndexTrackingBackgroundColor = UIColorHex(@"#f5f5f5");
    self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
//    self.tableView.dataSource = self;
//    self.tableView.delegate = self;
    self.tableView.rowHeight = 56.f;
    self.tableView.tableHeaderView.hidden = NO;
    [self.tableView mh_registerCell:[MHCommonTableViewCell class]];
    //    [self.viewModel.requstAskCountCommand execute:nil];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tableView.emptyDataSetDelegate = nil;
    self.tableView.emptyDataSetSource = nil;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UIEdgeInsets)contentInset
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datas.count;
}
//
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MHCommonTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"MHCommonTableViewCell" forIndexPath:indexPath];
    AMapTip *tip = self.datas[indexPath.row];
    cell.textLabel.text = tip.name;
    cell.descriptionLabel.text = tip.address;
    cell.rightImageView.hidden = YES;
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AMapTip *tip = self.datas[indexPath.row];
    if (self.selectCompleteBlock) {
        self.selectCompleteBlock(tip);
    }

}

-(void)searchBarTextShouldReturn:(JKRSearchBar *)searchBar
{
    if (searchBar.text.length > 0) {
        [self.view endEditing:YES];
//        self.viewModel.searchText = searchBar.text;
//        [searchBar resignFirstResponder];
//        [self.viewModel.requestRemoteDataCommand execute:@(1)];
        self.tableView.emptyDataSetDelegate = self;
        self.tableView.emptyDataSetSource = self;
    }
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString *text = @"没有搜索到相关圈子";
    
    NSDictionary *attributes = @{NSFontAttributeName: MHRegularFont_15,
                                 NSForegroundColorAttributeName: MHMetionTextColor};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (void)searchBarTextDidEndEditing:(JKRSearchBar *)searchBar {
}



- (void)searchBar:(JKRSearchBar *)searchBar textDidChange:(NSString *)searchText {
}
@end
